package com.xone.xapp;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	
	protected static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	public static final String format(Date date, String format) {
		String result = null;
		try {
			result = new SimpleDateFormat(format).format(date);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static final String format(Date date) {
		return format(date, DEFAULT_DATE_FORMAT);
	}
	
	public static final Date parseDate(String date) {
		return parseDate(date, DEFAULT_DATE_FORMAT);
	}
	
	public static final Date parseDate(String date, String pattern) {
		try {
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
			simpleDateFormat.applyPattern(pattern);
            return simpleDateFormat.parse(date);
        } catch (Exception e) {
        }
		return null;
	}
}
